package testing.control;

import java.awt.event.KeyEvent;

import utilities.control.enums.KeyEventType;
import utilities.control.keyboard.iface.KeyControlScheme;

/** <code>TestKeyControlScheme</code><br>
 * <br>
 * A testing example of the <code>KeyControlScheme</code> interface. It takes keyboard inputs
 * from the player and translates the inputs into string "commands".<br>
 * <br>
 * 
 * @author CoconutTank
 *
 */
public class TestKeyControlScheme implements KeyControlScheme
{
	/**
	 * 
	 */
	public static final String PAUSE = "PAUSE";
	public static final String EXIT = "EXIT";
	public static final String PRIMARY = "PRIMARY";
	public static final String ALTERNATE = "ALTERNATE";

	/**
	 * 
	 */
	public static final String UP = "UP";
	public static final String DOWN = "DOWN";
	public static final String LEFT = "LEFT";
	public static final String RIGHT = "RIGHT";
	
	/**
	 * 
	 */
	public static final String HOLD = "HOLD";
	public static final String RELEASE = "RELEASE";
	
	public String keyToCommand(KeyEventType t, KeyEvent e) 
	{
		if(e != null)
		{
			if(KeyEventType.KEY_TYPED_EVENT.equals(t)
			   || KeyEventType.KEY_PRESSED_EVENT.equals(t))
			{
				if(e.getKeyCode() == KeyEvent.VK_UP
				   || e.getKeyCode() == KeyEvent.VK_W)
				{
					return HOLD + "," + UP;
				}
				else if(e.getKeyCode() == KeyEvent.VK_DOWN
						|| e.getKeyCode() == KeyEvent.VK_S)
				{
					return HOLD + "," + DOWN;
				}
				else if(e.getKeyCode() == KeyEvent.VK_LEFT
						|| e.getKeyCode() == KeyEvent.VK_A)
				{
					return HOLD + "," + LEFT;
				}
				else if(e.getKeyCode() == KeyEvent.VK_RIGHT
						|| e.getKeyCode() == KeyEvent.VK_D)
				{
					return HOLD + "," + RIGHT;
				}
			}
			else if(KeyEventType.KEY_RELEASED_EVENT.equals(t))
			{
				if(e.getKeyCode() == KeyEvent.VK_UP
				   || e.getKeyCode() == KeyEvent.VK_W)
				{
					return RELEASE + "," + UP;
				}
				else if(e.getKeyCode() == KeyEvent.VK_DOWN
						|| e.getKeyCode() == KeyEvent.VK_S)
				{
					return RELEASE + "," + DOWN;
				}
				else if(e.getKeyCode() == KeyEvent.VK_LEFT
						|| e.getKeyCode() == KeyEvent.VK_A)
				{
					return RELEASE + "," + LEFT;
				}
				else if(e.getKeyCode() == KeyEvent.VK_RIGHT
						|| e.getKeyCode() == KeyEvent.VK_D)
				{
					return RELEASE + "," + RIGHT;
				}
			}
		}
		
		return null;
	}
}
